package net.controller;


import net.pojo.Artile;
import net.pojo.Comments;
import net.pojo.Links;
import net.service.ArtileService;
import net.service.CommentsService;
import net.service.LinksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/links")
public class LinksController {
    @Autowired
    LinksService linksService;
    @Autowired
    ArtileService artileService;
    @Autowired
    CommentsService commentsService;

    @RequestMapping("/findAll")
    public String findAll(Model model, HttpSession session){
        session.setAttribute("result",2);
        List<Links> linksList = linksService.findAll();

        //根据点击量排行
        List<Artile> clickList = artileService.findByClick();
        //最新评论
        List<Comments> commentList = commentsService.findByCtime();
        model.addAttribute("linksList",linksList);
        model.addAttribute("clickList",clickList);
        model.addAttribute("commentList",commentList);
        return "/client/friendly.jsp";
    }

    @RequestMapping("/addlinks")
    @ResponseBody
    public Links addlinks(Links links){
        linksService.insertLinks(links);
        return links;
    }
}
